package org.stone.project.logWebBack.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.stone.project.common.pojo.annotation.Ds;
import org.stone.project.common.pojo.constant.SysConstant;
import org.stone.project.common.pojo.vo.R;
import org.stone.project.logInterface.pojo.po.MethodLog;
import org.stone.project.logInterface.pojo.po.RequestLog;
import org.stone.project.logWebBack.mapper.MethodLogMapper;
import org.stone.project.logWebBack.mapper.RequestLogMapper;
import org.stone.project.logWebBack.ro.MethodLogRo;
import org.stone.project.logWebBack.ro.RequestLogRo;

@Ds(SysConstant.LOG_DS_NAME)
@RestController
@RequestMapping("/monitor/log")
public class LogController {
    @Autowired
    private MethodLogMapper methodLogMapper;

    @Autowired
    private RequestLogMapper requestLogMapper;

    /**
     * 请求日志列表
     * @return
     */
    @GetMapping("listRequestLogPage")
    public R<PageInfo<RequestLog>> requestLogList(RequestLogRo requestLogRo){
        PageInfo<RequestLog> res = PageHelper.startPage(requestLogRo.getPageNum(), requestLogRo.getPageSize())
                .doSelectPageInfo(() -> {
                    requestLogMapper.selectRequestLogList(requestLogRo);
                });
        return R.ok(res);
    }

    /**
     * 方法日志列表
     * @return
     */
    @GetMapping("listMethodLogPage")
    public R<PageInfo<MethodLog>> methodLogList(MethodLogRo methodLogRo){
        PageInfo<MethodLog> res = PageHelper.startPage(methodLogRo.getPageNum(), methodLogRo.getPageSize())
                .doSelectPageInfo(() -> {
                    methodLogMapper.selectMethodLogList(methodLogRo);
                });
        return R.ok(res);
    }
}
